package com.squad.springbootdemo.controller;

import com.squad.springbootdemo.mapper.QuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: LiamLMK
 * @CreateTime: 2025-03-14
 * @Description: 供测试
 * @Version: 1.0
 */

@RestController
public class TestController {

    @Autowired
    QuestionMapper questionMapper;

    @RequestMapping("/ask")
    public String askQuestion(
            @RequestParam("content") String questionContent,
            @RequestParam(name = "asker", required = false) String asker,
            @RequestParam(name = "question_no", required = false) String questionNo
    ) {
        System.out.println("run test function");
        System.out.println("提问的内容是：" + questionContent);

        //保存问题内容及属性到数据库
        int count = questionMapper.saveQuestion(questionContent, asker, questionNo);

        String resultText;
        if(count > 0)
            resultText = "insert successfully";
        else
            resultText = "insert failed";

        System.out.println(resultText);
        return resultText;
    }
}
